/*
  学习目标：实现父传子
 
*/

import React from 'react';

export default class Parent extends React.Component {
  state = {
    money: 1000,
  };

  handleMakeMoney = () => {
    this.setState({
      money: 1000 + this.state.money,
    });
  };

  render() {
    const { money } = this.state;
    return (
      <div>
        <h1>{money}</h1>
        <button onClick={this.handleMakeMoney}>爸爸开始赚钱了</button>
        {/* 1.  */}
        <Child money={money / 2}></Child>
      </div>
    );
  }
}

class Child extends React.Component {
  render() {
    // 2.
    const { money } = this.props;
    return (
      <div>
        <h1>爸爸给我钱了： {money}</h1>
      </div>
    );
  }
}
